using UnityEngine;
using UnityEngine.UI;

public class RCC_PhotonManager : MonoBehaviour
{
	public Transform spawnPoint;

	public GameObject startButton;

	public GameObject chat;

	public InputField playerName;

	private void Start()
	{
		playerName.gameObject.SetActive(false);
		startButton.SetActive(false);
		chat.SetActive(false);
		ConnectToServer();
	}

	private void ConnectToServer()
	{
		MonoBehaviour.print("Connecting To Photon Server");
		if (PhotonNetwork.connectionState == ConnectionState.Connected)
		{
			PhotonNetwork.Disconnect();
		}
		PhotonNetwork.ConnectUsingSettings("RCC V3.0f");
	}

	private void OnGUI()
	{
		if (PhotonNetwork.connectionState != ConnectionState.Connected)
		{
			GUI.color = Color.red;
		}
		GUILayout.Label("State: " + PhotonNetwork.connectionStateDetailed);
		GUI.color = Color.white;
		GUILayout.Label("Total Player Count: " + PhotonNetwork.playerList.Length);
		GUILayout.Label("Ping: " + PhotonNetwork.GetPing());
	}

	private void OnJoinedLobby()
	{
		MonoBehaviour.print("Joined Lobby");
		PhotonNetwork.JoinRandomRoom();
	}

	private void OnPhotonRandomJoinFailed()
	{
		MonoBehaviour.print("Joining to random room has failed!, Creating new room...");
		PhotonNetwork.CreateRoom(null);
	}

	private void OnJoinedRoom()
	{
		MonoBehaviour.print("Joined Room");
		playerName.gameObject.SetActive(true);
	}

	public void SetPlayerName(string name)
	{
		PhotonNetwork.playerName = name;
		playerName.gameObject.SetActive(false);
		chat.SetActive(true);
		startButton.SetActive(true);
	}
}
